export const commonRules = {
    data() {
        // 验证手机号的规则
        var checkMobile = (rule, value, cb) => {
            const regMobile = /^1[0-9]\d{9}$/


            // if (regMobile.text(value)) 
            if (regMobile.test(value) == true) {
                return cb()
            }

            cb(new Error('请输入合法的手机号'))
        }
        return {
            addFormRules: {
                username: [
                    { required: true, min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: ['blur', 'change'] }
                ],
                password: [
                    { required: true, message: '请输入密码', trigger: 'blur' },
                    { min: 5, max: 10, message: '长度在 5 到 10 个字符', trigger: ['blur', 'change'] }
                ],
                email: [
                    { required: true, message: '请输入邮箱地址', trigger: 'blur' },
                    { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }
                ],
                mobile: [
                    { required: true, message: '请输入手机号', trigger: 'blur' },
                    { validator: checkMobile, trigger: ['blur', 'change'] }
                ],
            },
            editFormRules: {
                email: [
                    { required: true, message: '请输入邮箱地址', trigger: 'blur' },
                    { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }

                ],
                mobile: [
                    { required: true, message: '请输入手机号', trigger: 'blur' },
                    { validator: checkMobile, trigger: ['blur', 'change'] }

                ]
            },

            addRolesFormRules: {
                roleName: [
                    // 发送请求这个是必须的，所以不需要重定向影响美观，如果为空请求会动态返送用户名不能为空
                    { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: ['blur', 'change'] }
                ],
                roleDesc: [
                    { required: true, message: '请输入密码', trigger: 'blur' },
                    { min: 5, max: 10, message: '长度在 5 到 10 个字符', trigger: ['blur', 'change'] }
                ],
            },
            // 这是表单的验证规则对象
            LoginRules: {
                username: [
                    { required: true, message: '请输入用户名', trigger: 'blur' },
                    { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                ],
                password: [
                    { required: true, message: '请输入用户密码', trigger: 'blur' },
                    { min: 5, max: 12, message: '长度在 5 到 12 个字符', trigger: 'blur' }
                ]
            },
            editCateRules: {
                cat_name: [
                    { required: true, message: '请输入要修改的信息', trigger: ['blur'] }

                ]
            },

            // 分类表单的验证规则对象
            addCateFormRules: {
                cat_name: [
                    { required: true, message: '请输入分类名', trigger: 'blur' },
                    { min: 1, max: 10, message: '长度在 1 到 10 个字符', trigger: ['blur', 'change'] }
                ],
            },
        }
    },
}

export const paramsRules = {
    data() {
        return {
            addFormRules: {
                attr_name: [
                    { required: true, message: '请输入添加的分类', trigger: 'blur' },
                ]

            },

            editFormRules: {
                attr_name: [
                    { required: true, message: '分类名不能为空', trigger: 'blur' },
                ]

            },
        }
    }

}
export const addRules = {
    data() {
        return {
            addFormRules: {
                goods_name: [
                    { required: true, message: '请输入商品的名称', trigger: 'blur' },
                    {
                        min: 2,
                        max: 30,
                        message: '请输入 2 ~ 30 范围的字符',
                        trigger: 'blur'
                    }
                ],
                goods_price: [{ required: true, message: '请输入商品的价格', trigger: 'blur' }],
                goods_weight: [{ required: true, message: '请输入商品的重量', trigger: 'blur' }],
                goods_number: [{ required: true, message: '请输入商品的数量', trigger: 'blur' }],
                goods_cat: [{ required: true, message: '请选择商品分类', trigger: 'blur' }],


            },

        }
    }
}

export const orderRules = {
    data() {
        return {
            addFormRules:{
                address1: [{ required: true}],

                address2: [{ required: true, message: '请填写详细地址',trigger: 'blur'}]

            }
        }
    },
}
